package guiclient;

import client.ClientSession;
import command.client.AcceptInvitationClient;
import java.awt.Color;

public class GUIInvitationToChat extends javax.swing.JDialog {

    private String userInvites;
    private String conversationID;
    private Color colorBackgroud = new Color(240, 240, 240);
    private ClientSession client;

    public GUIInvitationToChat(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        getContentPane().setBackground(colorBackgroud);
    }

    public GUIInvitationToChat(java.awt.Frame parent, boolean modal,
            String userNickName, String idOfConversation, ClientSession session) {
        super(parent, modal);
        initComponents();
        getContentPane().setBackground(colorBackgroud);
        userInvites = userNickName;
        conversationID = idOfConversation;
        client = session;
        userInvitesYouJLabel.setText(userInvites);
        setVisible(true);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        acceptInvitationJLabel = new javax.swing.JLabel();
        userInvitesYouJLabel = new javax.swing.JLabel();
        invitationQuestionJLabel = new javax.swing.JLabel();
        acceptInvitationJButton = new javax.swing.JButton();
        refuseInvitationJButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        acceptInvitationJLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        acceptInvitationJLabel.setText("Has sido invitado para unirte a una conversación. Te ha invitado: ");

        userInvitesYouJLabel.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        userInvitesYouJLabel.setForeground(new java.awt.Color(0, 0, 204));
        userInvitesYouJLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        userInvitesYouJLabel.setText("jLabel2");

        invitationQuestionJLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        invitationQuestionJLabel.setText("¿Deseas unirte a la conversación?");

        acceptInvitationJButton.setText("Aceptar Invitación");
        acceptInvitationJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                acceptInvitationJButtonActionPerformed(evt);
            }
        });

        refuseInvitationJButton.setText("Rechazar Invitación");
        refuseInvitationJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                refuseInvitationJButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(invitationQuestionJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(acceptInvitationJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(userInvitesYouJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(acceptInvitationJButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(refuseInvitationJButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(acceptInvitationJLabel)
                .addGap(18, 18, 18)
                .addComponent(userInvitesYouJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(invitationQuestionJLabel)
                .addGap(18, 18, 18)
                .addComponent(acceptInvitationJButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(refuseInvitationJButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void refuseInvitationJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refuseInvitationJButtonActionPerformed
        setVisible(false);
    }//GEN-LAST:event_refuseInvitationJButtonActionPerformed

    private void acceptInvitationJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptInvitationJButtonActionPerformed
        AcceptInvitationClient command = new AcceptInvitationClient();
        command.setConversationID(conversationID);
        command.execute(client, false);
        this.dispose();
    }//GEN-LAST:event_acceptInvitationJButtonActionPerformed

    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
                javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUIInvitationToChat.class.getName()).log(
                    java.util.logging.Level.SEVERE,
                    "Fallo al iniciar la ventana de invitación a conversación", ex);
        }
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                GUIInvitationToChat dialog = new GUIInvitationToChat(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton acceptInvitationJButton;
    private javax.swing.JLabel acceptInvitationJLabel;
    private javax.swing.JLabel invitationQuestionJLabel;
    private javax.swing.JButton refuseInvitationJButton;
    private javax.swing.JLabel userInvitesYouJLabel;
    // End of variables declaration//GEN-END:variables
}
